package com.dfrz.household.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dfrz.household.bean.Company;
import com.dfrz.household.mapper.CompanyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class CompanyServiceImpl implements ICompanyService {
    @Autowired
    CompanyMapper companyMapper;
    @Override
    public List<Company> getAllCompany() {
       List<Company> list = new ArrayList<Company>();
       list=companyMapper.getAllCompany();
       return list;

    }

    @Override
    public List<Company> getCompaniesByPage(int currPage, int pageSize) {
        List<Company> list = new ArrayList<Company>();
        list=companyMapper.getAllCompany();

        //        从第几条数据开始
        int firstIndex = (currPage - 1) * pageSize;
//        到第几条数据结束
        int lastIndex = currPage * pageSize;
        return list.subList(firstIndex, lastIndex);
    }

    @Override
    public Company getOneCompanyById(Integer id) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("mid",id);
       Company company= companyMapper.selectOne(wrapper);
       return company;
    }
}
